/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class Tags
    {
    
        private String distinctTagsField;

        private String distinctItemsField;

        private String distinctUsersField;

        private String totalUsagesField;

        private  Tagging firstTaggingField;
        private  Tagging lastTaggingField;
        private  List<Tag> tagField;


        /// <summary>
        /// Gets and sets the DistinctTags property.
        /// </summary>
        [XmlElementAttribute(ElementName = "DistinctTags")]
        public String DistinctTags
        {
            get { return this.distinctTagsField ; }
            set { this.distinctTagsField= value; }
        }



        /// <summary>
        /// Sets the DistinctTags property
        /// </summary>
        /// <param name="distinctTags">DistinctTags property</param>
        /// <returns>this instance</returns>
        public Tags WithDistinctTags(String distinctTags)
        {
            this.distinctTagsField = distinctTags;
            return this;
        }



        /// <summary>
        /// Checks if DistinctTags property is set
        /// </summary>
        /// <returns>true if DistinctTags property is set</returns>
        public Boolean IsSetDistinctTags()
        {
            return  this.distinctTagsField != null;

        }


        /// <summary>
        /// Gets and sets the DistinctItems property.
        /// </summary>
        [XmlElementAttribute(ElementName = "DistinctItems")]
        public String DistinctItems
        {
            get { return this.distinctItemsField ; }
            set { this.distinctItemsField= value; }
        }



        /// <summary>
        /// Sets the DistinctItems property
        /// </summary>
        /// <param name="distinctItems">DistinctItems property</param>
        /// <returns>this instance</returns>
        public Tags WithDistinctItems(String distinctItems)
        {
            this.distinctItemsField = distinctItems;
            return this;
        }



        /// <summary>
        /// Checks if DistinctItems property is set
        /// </summary>
        /// <returns>true if DistinctItems property is set</returns>
        public Boolean IsSetDistinctItems()
        {
            return  this.distinctItemsField != null;

        }


        /// <summary>
        /// Gets and sets the DistinctUsers property.
        /// </summary>
        [XmlElementAttribute(ElementName = "DistinctUsers")]
        public String DistinctUsers
        {
            get { return this.distinctUsersField ; }
            set { this.distinctUsersField= value; }
        }



        /// <summary>
        /// Sets the DistinctUsers property
        /// </summary>
        /// <param name="distinctUsers">DistinctUsers property</param>
        /// <returns>this instance</returns>
        public Tags WithDistinctUsers(String distinctUsers)
        {
            this.distinctUsersField = distinctUsers;
            return this;
        }



        /// <summary>
        /// Checks if DistinctUsers property is set
        /// </summary>
        /// <returns>true if DistinctUsers property is set</returns>
        public Boolean IsSetDistinctUsers()
        {
            return  this.distinctUsersField != null;

        }


        /// <summary>
        /// Gets and sets the TotalUsages property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TotalUsages")]
        public String TotalUsages
        {
            get { return this.totalUsagesField ; }
            set { this.totalUsagesField= value; }
        }



        /// <summary>
        /// Sets the TotalUsages property
        /// </summary>
        /// <param name="totalUsages">TotalUsages property</param>
        /// <returns>this instance</returns>
        public Tags WithTotalUsages(String totalUsages)
        {
            this.totalUsagesField = totalUsages;
            return this;
        }



        /// <summary>
        /// Checks if TotalUsages property is set
        /// </summary>
        /// <returns>true if TotalUsages property is set</returns>
        public Boolean IsSetTotalUsages()
        {
            return  this.totalUsagesField != null;

        }


        /// <summary>
        /// Gets and sets the FirstTagging property.
        /// </summary>
        [XmlElementAttribute(ElementName = "FirstTagging")]
        public Tagging FirstTagging
        {
            get { return this.firstTaggingField ; }
            set { this.firstTaggingField = value; }
        }



        /// <summary>
        /// Sets the FirstTagging property
        /// </summary>
        /// <param name="firstTagging">FirstTagging property</param>
        /// <returns>this instance</returns>
        public Tags WithFirstTagging(Tagging firstTagging)
        {
            this.firstTaggingField = firstTagging;
            return this;
        }



        /// <summary>
        /// Checks if FirstTagging property is set
        /// </summary>
        /// <returns>true if FirstTagging property is set</returns>
        public Boolean IsSetFirstTagging()
        {
            return this.firstTaggingField != null;
        }




        /// <summary>
        /// Gets and sets the LastTagging property.
        /// </summary>
        [XmlElementAttribute(ElementName = "LastTagging")]
        public Tagging LastTagging
        {
            get { return this.lastTaggingField ; }
            set { this.lastTaggingField = value; }
        }



        /// <summary>
        /// Sets the LastTagging property
        /// </summary>
        /// <param name="lastTagging">LastTagging property</param>
        /// <returns>this instance</returns>
        public Tags WithLastTagging(Tagging lastTagging)
        {
            this.lastTaggingField = lastTagging;
            return this;
        }



        /// <summary>
        /// Checks if LastTagging property is set
        /// </summary>
        /// <returns>true if LastTagging property is set</returns>
        public Boolean IsSetLastTagging()
        {
            return this.lastTaggingField != null;
        }




        /// <summary>
        /// Gets and sets the Tag property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Tag")]
        public List<Tag> Tag
        {
            get
            {
                if (this.tagField == null)
                {
                    this.tagField = new List<Tag>();
                }
                return this.tagField;
            }
            set { this.tagField =  value; }
        }



        /// <summary>
        /// Sets the Tag property
        /// </summary>
        /// <param name="list">Tag property</param>
        /// <returns>this instance</returns>
        public Tags WithTag(params Tag[] list)
        {
            foreach (Tag item in list)
            {
                Tag.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks if Tag property is set
        /// </summary>
        /// <returns>true if Tag property is set</returns>
        public Boolean IsSetTag()
        {
            return (Tag.Count > 0);
        }




        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetDistinctTags()) {
                xml.Append("<DistinctTags>");
                xml.Append(EscapeXML(this.DistinctTags));
                xml.Append("</DistinctTags>");
            }
            if (IsSetDistinctItems()) {
                xml.Append("<DistinctItems>");
                xml.Append(EscapeXML(this.DistinctItems));
                xml.Append("</DistinctItems>");
            }
            if (IsSetDistinctUsers()) {
                xml.Append("<DistinctUsers>");
                xml.Append(EscapeXML(this.DistinctUsers));
                xml.Append("</DistinctUsers>");
            }
            if (IsSetTotalUsages()) {
                xml.Append("<TotalUsages>");
                xml.Append(EscapeXML(this.TotalUsages));
                xml.Append("</TotalUsages>");
            }
            if (IsSetFirstTagging()) {
                Tagging  firstTagging = this.FirstTagging;
                xml.Append("<FirstTagging>");
                xml.Append(firstTagging.ToXMLFragment());
                xml.Append("</FirstTagging>");
            } 
            if (IsSetLastTagging()) {
                Tagging  lastTagging = this.LastTagging;
                xml.Append("<LastTagging>");
                xml.Append(lastTagging.ToXMLFragment());
                xml.Append("</LastTagging>");
            } 
            List<Tag> tagList = this.Tag;
            foreach (Tag tag in tagList) {
                xml.Append("<Tag>");
                xml.Append(tag.ToXMLFragment());
                xml.Append("</Tag>");
            }
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}